<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 题目1(选做)：const arr=['name','age','hhh','hhh','age','hhh','hhh','hhh'] 元素各出现多少次
      // 要求输出一个对象如下：{age: 2,hhh: 5,name: 1}
      const arr = ['name', 'age', 'hhh', 'hhh', 'age', 'hhh', 'hhh', 'hhh']
      const acc = {}
      for (let i = 0; i < arr.length; i++) {
        if (acc[arr[i]]) {
          acc[arr[i]]++
        } else {
          acc[arr[i]] = 1
        }
      }
      console.log(acc)
    </script>
  </body>
</html>
